package com.skyward.android.androiddemo2;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.skyward.android.androiddemo2.fragment.NewsFragment;
import com.skyward.android.androiddemo2.view.ViewPagerIndicator;

public class IndicateActivity extends AppCompatActivity {

    private ViewPager mViewPager;
    private String [] array ={"头条","娱乐","八卦","科技","体育","影视歌","亲子节目","本地信息","游戏","互联网","房地产","旅游"};
    private ViewPagerIndicator mViewPagerIndicator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_indicate);
        mViewPager = (ViewPager) findViewById(R.id.viewpager);
        mViewPagerIndicator = (ViewPagerIndicator) findViewById(R.id.viewPagerIndicator);
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {

                return  NewsFragment.getInstance(array[position]);
            }

            @Override
            public int getCount() {
                return array.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return array[position];
            }
        });
        mViewPagerIndicator.setViewPager(mViewPager);
    }
}
